<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - rectangle_abstract.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2005  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#undef</font> DLIB_RECTANGLe_ABSTRACT_
<font color='#0000FF'>#ifdef</font> DLIB_RECTANGLe_ABSTRACT_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='vector_abstract.h.html'>vector_abstract.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iostream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../serialize.h.html'>../serialize.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

    <font color='#0000FF'>class</font> <b><a name='rectangle'></a>rectangle</b>
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                The initial value of this object is defined by its constructor.                

            WHAT THIS OBJECT REPRESENTS
                This object represents a rectangular region inside a Cartesian 
                coordinate system.  The region is the rectangle with its top 
                left corner at position (left(),top()) and its bottom right corner 
                at (right(),bottom()).

                Note that the origin of the coordinate system, i.e. (0,0), is located
                at the upper left corner.  That is, points such as (1,1) or (3,5) 
                represent locations that are below and to the right of the origin.

                Also note that rectangles where top() &gt; bottom() or left() &gt; right() 
                represent empty rectangles.
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #*this represents the same rectangle as rect
        !*/</font>

        <b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #left() == 0
                - #top() == 0
                - #right() == -1 
                - #bottom() == -1 
                - #is_empty() == true
        !*/</font>

        <b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> left_,
            <font color='#0000FF'><u>long</u></font> top_,
            <font color='#0000FF'><u>long</u></font> right_,
            <font color='#0000FF'><u>long</u></font> bottom_
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #left() == left_
                - #top() == top_
                - #right() == right_
                - #bottom() == bottom_
        !*/</font>

        <b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width_,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height_
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            requires
                - (width_ &gt; 0 &amp;&amp; height_ &gt; 0) || (width_ == 0 &amp;&amp; height_ == 0)
            ensures
                - #left() == 0  
                - #top() == 0
                - #width() == width_
                - #height() == height_
        !*/</font>

        <b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #left()   == p.x()
                - #top()    == p.y()
                - #right()  == p.x()
                - #bottom() == p.y()
        !*/</font>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
        <b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p1,
            <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p2
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #*this == rectangle(p1) + rectangle(p2)
        !*/</font>

        <font color='#0000FF'><u>long</u></font> <b><a name='left'></a>left</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns the x coordinate for the left side of this rectangle
        !*/</font>

        <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> <b><a name='left'></a>left</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - returns a non-const reference to the x coordinate for the left side 
                  of this rectangle
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_left'></a>set_left</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> left_
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #left() == left_
        !*/</font>

        <font color='#0000FF'><u>long</u></font> <b><a name='top'></a>top</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns the y coordinate for the top of this rectangle
        !*/</font>

        <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> <b><a name='top'></a>top</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - returns a non-const reference to the y coordinate for the 
                  top of this rectangle
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_top'></a>set_top</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> top_
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #top() == top_
        !*/</font>

        <font color='#0000FF'><u>long</u></font> <b><a name='right'></a>right</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns the x coordinate for the right side of this rectangle
        !*/</font>

        <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> <b><a name='right'></a>right</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - returns a non-const reference to the x coordinate for the right 
                  side of this rectangle
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_right'></a>set_right</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> right_
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #right() == right_
        !*/</font>

        <font color='#0000FF'><u>long</u></font> <b><a name='bottom'></a>bottom</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns the y coordinate for the bottom of this rectangle
        !*/</font>
       
        <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> <b><a name='bottom'></a>bottom</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - returns a non-const reference to the y coordinate for the bottom 
                  of this rectangle
        !*/</font>
       
        <font color='#0000FF'><u>void</u></font> <b><a name='set_bottom'></a>set_bottom</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> bottom_
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #bottom() == bottom_
        !*/</font>

        <font color='#0000FF'>const</font> point <b><a name='tl_corner'></a>tl_corner</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns point(left(), top()) 
                  (i.e. returns the top left corner point for this rectangle)
        !*/</font>

        <font color='#0000FF'>const</font> point <b><a name='bl_corner'></a>bl_corner</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns point(left(), bottom()) 
                  (i.e. returns the bottom left corner point for this rectangle)
        !*/</font>

        <font color='#0000FF'>const</font> point <b><a name='tr_corner'></a>tr_corner</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns point(right(), top()) 
                  (i.e. returns the top right corner point for this rectangle)
        !*/</font>

        <font color='#0000FF'>const</font> point <b><a name='br_corner'></a>br_corner</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns point(right(), bottom()) 
                  (i.e. returns the bottom right corner point for this rectangle)
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='is_empty'></a>is_empty</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (top() &gt; bottom() || left() &gt; right()) then
                    - returns true
                - else
                    - returns false
        !*/</font>

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='width'></a>width</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (is_empty()) then
                    - returns 0
                - else
                    - returns the width of this rectangle.
                      (i.e. right() - left() + 1)
        !*/</font>

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='height'></a>height</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (is_empty()) then
                    - returns 0
                - else
                    - returns the height of this rectangle.
                      (i.e. bottom() - top() + 1)
        !*/</font>

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='area'></a>area</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns width()*height()
        !*/</font>

        rectangle <b><a name='operator'></a>operator</b> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rhs
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (rhs.is_empty() == false &amp;&amp; this-&gt;is_empty() == false) then
                    - returns the smallest rectangle that contains both *this and 
                      rhs.
                - if (rhs.is_empty() == true &amp;&amp; this-&gt;is_empty() == false) then
                    - returns *this
                - if (rhs.is_empty() == false &amp;&amp; this-&gt;is_empty() == true) then
                    - returns rhs
                - if (rhs.is_empty() == true &amp;&amp; this-&gt;is_empty() == true) then
                    - returns a rectangle that has is_empty() == true
        !*/</font>

        rectangle <b><a name='intersect'></a>intersect</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rhs
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (there is a region of intersection between *this and rhs) then
                    - returns a rectangle that represents the intersection of *this 
                      and rhs.
                - else
                    - returns a rectangle where is_empty() == true
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='contains'></a>contains</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (the point (x,y) is contained in this rectangle) then
                    - returns true
                - else
                    - returns false
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='contains'></a>contains</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (the point (p.x(),p.y()) is contained in this rectangle) then
                    - returns true
                - else
                    - returns false
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='contains'></a>contains</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (rect + *this == *this) then
                    - returns true
                      (i.e. returns true if *this contains the given rectangle)
                - else
                    - returns false
        !*/</font>

        rectangle<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #*this represents the same rectangle as rect
                - returns #*this
        !*/</font>

        rectangle<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - #*this == *this + rect 
                - returns #*this
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - if (top() == rect.top() &amp;&amp; left() == rect.left() &amp;&amp;
                      right() == rect.right() &amp;&amp; bottom() == rect.bottom()) then
                    - returns true
                - else
                    - returns false
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns !(*this == rect)
        !*/</font>

        <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&amp;</font> a,
            <font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&amp;</font> b
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - Defines a total ordering over rectangles so they can be used in
                  associative containers.
        !*/</font>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='serialize'></a>serialize</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> item, 
        std::ostream<font color='#5555FF'>&amp;</font> out
    <font face='Lucida Console'>)</font>;   
    <font color='#009900'>/*!
        provides serialization support 
    !*/</font>

    <font color='#0000FF'><u>void</u></font> <b><a name='deserialize'></a>deserialize</b> <font face='Lucida Console'>(</font>
        rectangle<font color='#5555FF'>&amp;</font> item, 
        std::istream<font color='#5555FF'>&amp;</font> in
    <font face='Lucida Console'>)</font>;   
    <font color='#009900'>/*!
        provides deserialization support 
    !*/</font>

    std::ostream<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>
        std::ostream<font color='#5555FF'>&amp;</font> out, 
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> item 
    <font face='Lucida Console'>)</font>;   
    <font color='#009900'>/*!
        ensures
            - writes item to out in the form "[(left, top) (right, bottom)]"
    !*/</font>

    std::istream<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>
        std::istream<font color='#5555FF'>&amp;</font> in, 
        rectangle<font color='#5555FF'>&amp;</font> item 
    <font face='Lucida Console'>)</font>;   
    <font color='#009900'>/*!
        ensures
            - reads a rectangle from the input stream in and stores it in #item.
              The data in the input stream should be of the form [(left, top) (right, bottom)]
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    point <b><a name='center'></a>center</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&amp;</font> rect
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns the center of the given rectangle
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <b><a name='dcenter'></a>dcenter</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&amp;</font> rect
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns the center of the given rectangle using a real valued vector.  
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='centered_rect'></a>centered_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - center(R) == p
                - if (width == 0 || height == 0)
                    - R.width() == 0 
                    - R.height() == 0 
                - else
                    - R.width() == width
                    - R.height() == height 
                - R.tl_corner() == point(p.x()-width/2, p.y()-height/2)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='centered_rect'></a>centered_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - center(R) == p
                - if (width == 0 || height == 0)
                    - R.width() == 0 
                    - R.height() == 0 
                - else
                    - R.width() == width
                    - R.height() == height 
                - R.tl_corner() == point(x-width/2, y-height/2)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='centered_rect'></a>centered_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns centered_rect( (rect.tl_corner() + rect.br_corner())/2, width, height)
              (i.e. returns a rectangle centered on rect but with the given width
              and height)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> rectangle <b><a name='set_aspect_ratio'></a>set_aspect_ratio</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>double</u></font> ratio
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - ratio &gt; 0
        ensures
            - This function reshapes the given rectangle so that it has the given aspect
              ratio.  In particular, this means we return a rectangle R such that the
              following equations are as true as possible:
                - R.width()/R.height() == ratio
                - R.area() == rect.area()
                - center(rect) == center(R)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> rectangle <b><a name='intersect'></a>intersect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> a,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a.intersect(b)
              (i.e. returns a rectangle representing the intersection of a and b)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='area'></a>area</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> a
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a.area()
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='shrink_rect'></a>shrink_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>long</u></font> num 
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns rectangle(rect.left()+num, rect.top()+num, rect.right()-num, rect.bottom()-num)
              (i.e. shrinks the given rectangle by shrinking its border by num)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='grow_rect'></a>grow_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>long</u></font> num 
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - return shrink_rect(rect, -num)
              (i.e. grows the given rectangle by expanding its border by num)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='shrink_rect'></a>shrink_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns rectangle(rect.left()+width, rect.top()+height, rect.right()-width, rect.bottom()-height)
              (i.e. shrinks the given rectangle by shrinking its left and right borders by width
              and its top and bottom borders by height. )
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='grow_rect'></a>grow_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - return shrink_rect(rect, -width, -height)
              (i.e. grows the given rectangle by expanding its border)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='translate_rect'></a>translate_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - R.left()   == rect.left()   + p.x()
                - R.right()  == rect.right()  + p.x()
                - R.top()    == rect.top()    + p.y()
                - R.bottom() == rect.bottom() + p.y()
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='translate_rect'></a>translate_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - R.left()   == rect.left()   + x
                - R.right()  == rect.right()  + x
                - R.top()    == rect.top()    + y
                - R.bottom() == rect.bottom() + y
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='resize_rect'></a>resize_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - if (width == 0 || height == 0)
                    - R.width() == 0 
                    - R.height() == 0 
                - else
                    - R.width() == width
                    - R.height() == height 
                - R.left() == rect.left() 
                - R.top() == rect.top() 
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='resize_rect_width'></a>resize_rect_width</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - R.width() == width
                - R.left() == rect.left() 
                - R.top() == rect.top() 
                - R.bottom() == rect.bottom() 
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='resize_rect_height'></a>resize_rect_height</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - R.height() == height 
                - R.left() == rect.left() 
                - R.top() == rect.top() 
                - R.right() == rect.right() 
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='move_rect'></a>move_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - R.width() == rect.width() 
                - R.height() == rect.height() 
                - R.left() == p.x()
                - R.top() == p.y() 
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='move_rect'></a>move_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y 
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns a rectangle R such that:
                - R.width() == rect.width() 
                - R.height() == rect.height() 
                - R.left() == x 
                - R.top() == y 
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> point <b><a name='nearest_point'></a>nearest_point</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - if (rect.contains(p)) then
                - returns p
            - else
                - returns the point in rect that is closest to p
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>size_t</u></font> <b><a name='nearest_rect'></a>nearest_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> rects,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - rects.size() &gt; 0
        ensures
            - returns the index of the rectangle that is closest to the point p.  In
              particular, this function returns an IDX such that:
                length(nearest_point(rects[IDX],p) - p)
              is minimized.
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>long</u></font> <b><a name='distance_to_rect_edge'></a>distance_to_rect_edge</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns the Manhattan distance between the edge of rect and p.
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T, <font color='#0000FF'>typename</font> U<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>double</u></font> <b><a name='distance_to_line'></a>distance_to_line</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::pair<font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font>,vector<font color='#5555FF'>&lt;</font>T,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> line,
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font>U,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns the euclidean distance between the given line and the point p.  That
              is, given a line that passes though the points line.first and line.second,
              what is the distance between p and the nearest point on the line?  This
              function returns that distance.
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='clip_line_to_rectangle'></a>clip_line_to_rectangle</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> box,
        point<font color='#5555FF'>&amp;</font> p1,
        point<font color='#5555FF'>&amp;</font> p2
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - clips the line segment that goes from points p1 to p2 so that it is entirely
              within the given box.  In particular, we will have:
                - box.contains(#p1) == true
                - box.contains(#p2) == true
                - The line segment #p1 to #p2 is entirely contained within the line segment
                  p1 to p2.  Moreover, #p1 to #p2 is the largest such line segment that
                  fits within the given box.
            - If the line segment does not intersect the box then the result is some
              arbitrary line segment inside the box.
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T 
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>const</font> rectangle <b><a name='get_rect'></a>get_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> m
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        requires
            - It must be possible to determine the number of "rows" and "columns" in m.
              Either by calling num_rows(m) and num_columns(m) or by calling m.nr() and
              m.nc() to obtain the number of rows and columns respectively.  Moreover,
              these routines should return longs.
        ensures
            - returns rectangle(0, 0, num_columns(m)-1, num_rows(m)-1)
              (i.e. assuming T represents some kind of rectangular grid, such as
              the dlib::matrix or dlib::array2d objects, this function returns the
              bounding rectangle for that gridded object.)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> rectangle <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r,
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns r + rectangle(p)
              (i.e. returns the rectangle that contains both r and p)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> rectangle <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p,
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r
    <font face='Lucida Console'>)</font>;
    <font color='#009900'>/*!
        ensures
            - returns r + rectangle(p)
              (i.e. returns the rectangle that contains both r and p)
    !*/</font>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_RECTANGLe_ABSTRACT_
</font>

</pre></body></html>